import Vue from "vue";
import Router from 'vue-router'
//引入组件
import home from '@/views/home'
import login from '@/views/login'
import layout from '@/Layout'

import gongdan from "@/views/gongdan"

Vue.use(Router)

export const routes = [
  {
    path: '/',
    name: 'layout',
    component: layout,
    // redirect: '/layout',
    children: [
      {
        path: '',
        name: 'home',
        component: home,
      },
      {
        path: 'gongdan',
        name: 'gongdan',
        component: gongdan,
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: login,
  },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()
//路由更新
export function resetRouter() {
  // 得到一个全新的 router 实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher // reset router
}
//暴露路由器
export default router